﻿using System.Collections.Generic;
using System.IO;

namespace RayDen.Library.Data.TFF
{
    public class TagFileService
    {

        private static TagInfo ReadTag(Stream str)
        {
            var result = new TagInfo();
            using (var reader = new BinaryReader(str))
            {
                var header = new TagHeader()
                    {
                        TagId = reader.ReadInt32(),
                        DataSize = reader.ReadInt32(),
                        TagVersion = reader.ReadInt32()
                    };
                result.Header = header;
                result.TagData = reader.ReadBytes(header.DataSize);
            }
            return result;
        }


        public static TagInfo[] OpenTagFile(string fileName)
        {
            var result = new List<TagInfo>();

            using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
            {
                result.Add(ReadTag(fs));

            }

            return result.ToArray();
        }
    }
}